import store from '@/common/store';

const _http = (method, preUrl, urlTail, data, response, error,base) =>{
	const httpDomain = store.getters.GET_httpDomain;
	const baseURL = base?base:store.state.baseURL;
	let loginToken = '';
	if(store.getters.GET_userInfo){
		loginToken = store.getters.GET_userInfo.token
	}
	
	let url = httpDomain+baseURL+preUrl+urlTail;
	console.log("url = " +url+ " authorization = " + loginToken );
	console.log(data);
	uni.request({
		method:method,
		url:url,
		data:{body:data},
		header:{
			'content-type': 'application/json',
			'authorization': loginToken,
		},
		success(res) {
			console.log(res)
			if(res.data.code == 198){
				console.log("跳转请登录")
				_login();
				return;
			}
			return response(res.data)
		},
		fail(err) {
			if(error){
				console.log(err)
				return error(err)
			}
		},
		complete(res) {
			if(res.statusCode==404||res.statusCode==505){
				uni.showModal({
					title:`系统异常${res.statusCode}`,
					content:"请联系客服",
					showCancel:false
				})
			}
		}
	})
}

const _login = () =>{
	uni.showModal({
		title:'当前登陆过期',
		content:'系统将重新登陆',
		showCancel:false,
		success() {
			if(store.state.autoLogin == true){
				const url = window.location.origin + window.location.pathname;
				const appId =  store.getters.GET_AppId;
				url = encodeURIComponent(url);
				window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='+appId
					+'&redirect_uri='+url
					+'&response_type=code&scope=snsapi_userinfo'
					+'&state=2#wechat_redirect';
			}else{
				wx.reLaunch({
					url:'/pages/login/login'
				})
			}
		}
	})
}

//接口
const _url = {
	//安全接口
	login:'login.do',
	resetPwd:'resetPwd.do',  //修改登录密码
	sendSMS:'sendSMS.do',    //发送手机验证码
	
	appConfig:'app/config.data',
		
	wxBind:'wx/bind.do',     //绑定微信公众号
	wxLogin:'wx/login.do',   //公众号登录
	wxSDK:'wx/jssdk/get.do', //JSSDK
	
	accountList:'account/list.data',    //获取登陆用户角色账号列表
	accountChange:'account/change.do',
	
	//公共接口-不检查权限
	commUserFind:'common/user/find.do',  				 //通过手机号（phone）查询用户
	commLogistics:'common/logistics_company/list.data',  //获取物流公司列表
	commBusinessTypeList:'common/business_type/select.data',  //业务类型
	
	funcModelRoleTypeList:'config/func_model/role_type/list.data',  //角色的功能模块
	busiTypeRoleTypeList:'config/business_type/role_type/list.data',	//角色的业务
	
	placeTypeList:'place/physical_store/type/select.data',  //网点类型 
	placeDeviceTypeList:'place/device_type/list.data',  	//网点类型设备列表
	
	/*上传图片*/
	upLoadImgPlace:'place/img/upload.do',  //上传网点相关图片
	upLoadImgUser:'user/img/upload.do',  //上传用户相关图片
	
	/*
		用户个人接口，通用不判断角色
	*/
	myWalletInfo:'my/wallet/info.data',                  //钱包详情
	myWalletOperateList:'my/wallet/operate/list.data',   //钱包流水
	
	/*钱包、提现及绑定*/
	transferWalletInfo:'transfer_money/wallet/info.data',
	transferApply:'transfer_money/apply.do',		  //提现申请
	transferWxBind:'transfer_money/wx_user/bind.do',  //微信账号绑定
	transferWxList:'transfer_money/wx_user/list.data',//微信账号列表
	transferQrBind:'transfer_money/qrcode/bind.do',   //二维码绑定
	transferQrInfo:'transfer_money/qrcode/info.data', //二维码详情
	
	funcModelList:'config/func_model/list.data',        //功能模块列表
	funcModelStateUpdate:'config/func_model/state/update.do',   //修改功能模块状态
	
	teamUserWalletInfo:'team/user/wallet/info.data',	 //团队用户钱包信息
	
	agentReferrerWalletList:'referrer_user/wallet/List.data',
	
	//=====检查权限=====//
	
	pay_account_list:'config/pay_account/list.data',
	pay_account_info:'config/pay_account/info.data',
	pay_account_user_wallet_list:'pay_account/user/wallet/list.data',
	
	//设备相关接口
	deviceList:'device/list.data',	     //设备列表
	deviceDistr:'device/distribute.do',  //设备分派
   
	//网点相关接口
	placeList:'place/physical_store/list.data',   	//网点列表，支持全部用户
	placeInfo:'place/physical_store/info.data',   	//网点详情，支持全部用户
	placeSave:'place/physical_store/save.do',       //保存网点，支持代理和员工
	placeCostTemplateChange:'place/business_config/cost/change.do',//网点切换价格，支持代理
	
	placeBusiConfigList:'place/business_config/list.data',   //网点业务信息，支持全部用户
	placeBusiTypeSave:'place/business_type/save.do',
	placeBusiDel:'place/business_config/del.do',     		 //删除网点业务信息，支持代理
	placeBusiTypeList:'place/business_type/list.data',		 //获取网点的业务类型列表，支持全部用户
	
	placeBusiConfigPCLList:'place/business_config/pcl/list.data',		//便携线充业务---------- 有点问题
	
	//网点-用户
	placeUserList:'place/user/list.data',   	//网点分成信息，支持代理
	placeUserSave:'place/user/save.do',			//保存网点用户信息，支持代理
	placeUserDel:'place/user/del.do',       	//删除网点用户信息，支持代理
	//网点-设备
	placeDeviceList:'place/device/list.data',          //网点设备列表 ，支持全部用户
	placeDeviceDeploy:'place/device/deploy.do',        //网点设备部署，支持代理和员工
	placeDeviceUndeploy:'place/device/undeploy.do',    //网点设备解绑，支持代理
	//网点-白名单
	placeFreeMemberList:'place/free_member/list.data',   	//网点白名单信息，支持代理
	placeFreeMemberSave:'place/free_member/save.do',		//保存网点白名单信息，支持代理
	placeFreeMemberDel:'place/free_member/del.do',       	//删除网点白名单信息，支持代理
	
	placeClerkList:'place/clerk/list.data',   	//网点店员信息
	placeClerkSave:'place/clerk/save.do',			//保存网点店员
	placeClerkDel:'place/clerk/del.do',       	//删除网点店员
	
	placeAddressSave:'place/physical_store/address/save.do',

	//会员-白名单
	freeMemberList:'free_member/list.data',
	
	//店员
	clerkList:'merchant/clerk/list.data',
	clerkInfo:'merchant/clerk/info.data',
	clerkAdd:'merchant/clerk/add.do',
	clerkPlaceList:'merchant/clerk/place/physical_store/list.data',
	clerkFuncModelList:'merchant/clerk/func_model/list.data',
	clerkFuncModelUpdate:'merchant/clerk/func_model/update.do',
	clerkPowerUpdate:'merchant/clerk/power/update.do',

	//订单相关接口
	orderList:'order/list.data',                  		//订单列表，支持全部用户
	orderOperateList:'order/operate_record/list.data',	//订单操作记录，支持全部用户
	orderProfitList:'order/profit/list.data',
	orderMemberCouponList:'member/order/coupon_activity/list.data',		//获取订单可发放的优惠券
	orderMemberCouponSet:'member/order/coupon_activity/set.do',		//发放优惠券
	
	//团队相关接口
	teamAdd:'team/user/add.do',            //添加团队成员
	teamUpdate:'team/user/update.do',   	//修改团队成员信息
	teamUserList:'team/user/list.data',        //团队成员列表
	teamUserInfo:'team/user/info.data',        //团队成员详情
	teamUserDeviceList:'team/user/device/list.data', //成员设备列表
	teamUserPlaceList:'team/user/place/physical_store/list.data', //成员网点列表
	teamUpdateFuncModel:'team/user/func_model/update.do', //修改用户功能模块
	teamUpdatePower:'team/user/power/update.do',
	teamSaveBusiConfig:'team/user/busi_config/save.do',
	teamDelBusiConfig:'team/user/busi_config/del.do',
	
	teamUserRoleTypeList:'team/user/role_type/list.data',
	
	teamUserTransferMoneyOrerList:'team/user/transfer_money_order/list.data',
	teamUserTransferMoneyOrerInfo:'team/user/transfer_money_order/info.data',
	teamUserTransferMoneyOrerRejec:'team/user/transfer_money_order/rejec.do',
	
	//充电插座相关接口
	cdczDevCount:'cdcz/device/count.data',
	cdczDevList:'cdcz/device/list.data',   //设备列表
	cdczDevInfo:'cdcz/device/info.data',   //设备详情
	cdczTestOpen:'cdcz/device/operate/charge.do',//测试充电
	
	cdczFeeList:'cdcz/fee_template/list.data',//价格模板列表
	cdczFeeSave:'cdcz/fee_template/save.do',  //保存价格模板
	cdczFeeDel:'cdcz/fee_template/del.do',    //删除价格模板
	
	/*--充电插座订单*/
	cdczOrderList:'cdcz/order/list.data',  	//订单列表
	cdczOrderDetail:'cdcz/order/info.data',				//充电桩订单详情
	cdczOrderCancel:'cdcz/order/cancel.do',				//订单撤销
	cdczOrderRefund:'cdcz/order/refund.do',				//部分退款
	cdczOrderFinish:'cdcz/order/finish.do',				//订单完成
	cdczOrderRecord:'cdcz/order/charge_record/list.data',//订单收费记录

	//共享充电宝相关接口
	cdbDevCount:'cdb/device/count.data',
	cdbDevList:'cdb/device/list.data',   //设备列表
	cdbDevInfo:'cdb/device/info.data',   //设备详情
	
	cdbTestOpen:'cdb/device/operate/eject.do',//测试弹出
	
	cdbFeeList:'cdb/fee_template/list.data',//价格模板列表
	cdbFeeSave:'cdb/fee_template/save.do',  //保存价格模板
	cdbFeeDel:'cdb/fee_template/del.do',    //删除价格模板

	/*充电宝订单*/
	cdbOrderList:'cdb/order/list.data',  	//订单列表
	cdbOrderDetail:'cdb/order/info.data',//充电宝订单详情
	cdbOrderCancel:'cdb/order/cancel.do',//订单撤销
	cdbOrderRefund:'cdb/order/refund.do',//部分退款
	cdbOrderFinish:'cdb/order/finish.do',//订单完成

	//便携式储能电池相关接口
	bxscnDevCount:'bxscn/device/count.data',
	bxscnDevList:'bxscn/device/list.data',
	bxscnDevInfo:'bxscn/device/info.data',   //设备详情
	
	bxscnTestOpen:'bxscn/device/operate/eject.do',//测试弹出
	
	bxscnFeeList:'bxscn/fee_template/list.data',	//价格模板列表
	bxscnFeeSave:'bxscn/fee_template/save.do',  	//保存价格模板
	bxscnFeeDel:'bxscn/fee_template/del.do',    	//删除价格模板
	
	bxscnShopFeeList:'bxscn/shop/fee_template/list.data',//价格模板列表
	bxscnShopFeeInfo:'bxscn/shop/fee_template/info.data',//价格模板列表
	bxscnShopFeeSave:'bxscn/shop/fee_template/save.do',  //保存价格模板
	bxscnShopFeeItemSave:'bxscn/shop/fee_template/item/save.do',  //保存价格模板
	bxscnShopFeeDel:'bxscn/shop/fee_template/del.do',    //删除价格模板
	bxscnShopFeeItemDel:'bxscn/shop/fee_template/item/del.do',    //删除价格模板
	
	bxscnBatteryList:'bxscn/battery/list.data', 		//储能电池列表
	bxscnBatteryInfo:'bxscn/battery/info.data',
	bxscnBatteryUnDeploy:'bxscn/battery/place/undeploy.do', 	//撤销部署 
	bxscnBatterySave:'bxscn/battery/save.do', 					//保存储能电池
	bxscnBatteryTypeList:'bxscn/battery/type/list.data', 		//储能电池类型列表
	bxscnBatteryOperate:'bxscn/battery/operate.do', 			//储能电池操作
	bxscnBatteryOperateResult:'bxscn/battery/operate/result.do', 	//储能电池操作结果
	bxscnBatteryLightOperate:'bxscn/battery/light/operate.do', 			//储能电池操作
	
	bxscnShopOrderList:'bxscn/shop/order/list.data',  	//门店订单
	bxscnShopOrderInfo:'bxscn/shop/order/info.data',  	//门店订单详情
	bxscnShopOrderRevert:'bxscn/shop/order/revert.do', //设备归还
	bxscnShopOrderLease:'bxscn/shop/order/lease.do',   //设备租借
	bxscnShopOrderFinish:'bxscn/shop/order/finish.do',
	bxscnShopOrderCancel:'bxscn/shop/order/cancel.do',
	bxscnShopOrderRefund:'bxscn/shop/order/refund.do',
	
	bxscnOrderList:'bxscn/order/list.data',  	//订单列表
	bxscnOrderInfo:'bxscn/order/info.data',  	//自助租借订单详情
	bxscnOrderCancel:'bxscn/order/cancel.do',	//订单撤销
	bxscnOrderRefund:'bxscn/order/refund.do',	//部分退款
	bxscnOrderFinish:'bxscn/order/finish.do',	//订单完成
	
	//便捷线充相关接口
	pclDevCount:'pcl/device/count.data',
	pclDevList:'pcl/device/list.data',
	
	pclFeeList:'pcl/fee_template/list.data',	//价格模板列表
	pclFeeSave:'pcl/fee_template/save.do',  	//保存价格模板
	pclFeeDel:'pcl/fee_template/del.do',    	//删除价格模板
	
	pclOrderList:'pcl/order/list.data',  	//订单列表
	pclOrderInfo:'pcl/order/info.data',  	//自助租借订单详情
	pclOrderCancel:'pcl/order/cancel.do',	//订单撤销
	pclOrderRefund:'pcl/order/refund.do',	//部分退款
	pclOrderFinish:'pcl/order/finish.do',	//订单完成

	//核销券 - 洗车券
	carWashSet:'order/verification_voucher/set.do',     //发送核销券
	
	carWashList:'member/verification_voucher/list.data',//列表
	carWashInfo:'member/verification_voucher/info.data',//详情
	carWashUse:'member/verification_voucher/use.do',    //核销
		
	/*统计*/
	statisticsInfo:'my/statistics/info.data',				//统计信息
	statisticsDayList:'my/statistics/profit/day/list.data',	//日收益统计列表
	statisticsDayInfo:'my/statistics/profit/day.data' 		//日收益详情接口
	
}

module.exports = {
	url:_url,
	post:(url,data,response,error) => _http('POST','/api/v1/',url,data,response,error),
	get:(url,data,response,error) => _http('GET','/api/v1/',url,data,response,error)
}